
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 2
 * @Author : WangRuoyu 
 * @Date : 2023/5/18 15:57
 */

#include "iostream"
#include "algorithm"

using namespace std;

int main() {
    int M = 10010;
    int cnt[M];
    for (int i = 0; i < M; ++i) {
        cnt[i] = 0;
    }
    int n;
    scanf("%d", &n);
    int a[n + 2];
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
    }

    n = unique(a + 1, a + n + 1) - a - 1;

    a[0] = 0;
    a[n + 1] = 0;

    for (int i = 1; i <= n; ++i) {
        int x = a[i - 1];
        int y = a[i];
        int z = a[i + 1];
        if (x < y && y > z) cnt[y]++;
        else if (x > y && y < z) cnt[y]--;
    }

    int res = 0;
    int sum = 0;
    for (int i = M - 1; i; i--) {
        sum += cnt[i];
        res = max(res, sum);
    }

    printf("%d", res);

    return 0;
}